package com.xiaouyudeguang.common.utils;

import com.xiaouyudeguang.common.console.Console;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

public class BaseUtils {

    public static String encode(String src) {
        return Base64.getEncoder().encodeToString(src.getBytes(StandardCharsets.UTF_8));
    }

    public static String encode(String src, int count) {
        do {
            src = encode(src);
            count--;
        } while (count > 0);
        return src;
    }

    public static String decode(String src) {
        return new String(Base64.getDecoder().decode(src.getBytes(StandardCharsets.UTF_8)));
    }

    public static boolean verify(String src, String encodeStr) {
        if (src.equals(encodeStr)) {
            return true;
        }
        if (src.length() > encodeStr.length()) {
            return false;
        }
        return verify(src, decode(encodeStr));
    }

    public static void main(String[] args) {
        Console.log(verify("1001", "VFZSQmQwMVJQVDA9"));
    }
}
